<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $starttime = $mtime;
?> 

<?php
session_start();

include("includes/database/dbconnect_mysql_procedural.inc");
//include("includes/functions/functions.php");
// i made a change here
?>


<?php
	
	if (isset($_POST['submit'])) {  

		$post_data = $_POST;
		
		$username = $post_data['username'];
		$password = $post_data['password'];
		
		//check to see if the username exists
		$sql = "SELECT count(user_id) FROM members WHERE username = '$username' AND password = '$password' LIMIT 1";
		$result = mysql_query($sql) or die(mysql_error());;
		
		
		if (mysql_result($result, 0) < 1){
			echo 'username or password does not exist';
	
		}
		
		if (empty($username)) {$errors['username_empty'] = 'Your Username is Required';}
		if (empty($password)) {$errors['password_empty'] = 'You Forgot Your Password';}
		//if ($username) {$errors['user_not_found'] = 'username or password dont match';}
		
		if (mysql_result($result, 0) > 0){ // and if there are no errors 
			echo 'found one';
			
			$sql = "SELECT username, first_name, last_name, email, referrer, member_status, gender FROM members WHERE username = '$username' AND password = '$password'";
			$result = mysql_query($sql) or die(mysql_error());
			
			$row = mysql_fetch_assoc($result);
			
			$_SESSION['username'] = $row['username'];
			
			$_SESSION['user_id'] = $row['user_id'];
			
			$_SESSION['gender'] = $row['gender'];
			$_SESSION['first_name'] = $row['first_name'];
			$_SESSION['last_name'] = $row['last_name'];
					
			$_SESSION['gdi_username'] = $row['gdi_username'];
			//$_SESSION['login_status'] = 'success';
			//$_SESSION['referrer'] = $row['referrer'];
			//$_SESSION['date_member_joined'] = $row['date_member_joined'];
			//$_SESSION['last_logged_in'] = $row['last_logged_in'];
			
			//$rightnow = date("Y-m-d H:i:s");
			
			//$sql = "UPDATE members SET last_logged_in='{$rightnow}' WHERE username='{$_SESSION[user_data][username]}'";
			//$result = mysql_query($sql) or die(mysql_error());
			
			
			$last_logged_in = date("m/d/Y h:i:s a");
			$sql_update_last_logged_in = "UPDATE members SET Last_logged_in='{$last_logged_in}' WHERE username='".$_SESSION['username']."'";
			$query = mysql_query($sql_update_last_logged_in) or die(mysql_error());

			header('Location: main.php');
		}
		

	} // end if 
	


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
	background-color: #465D7C;
}
#content {
	width: 617px;
	border: 3px none #111111;
	margin-right: auto;
	margin-left: auto;
	height: auto;
	background-color: #465D7C;
}
#container #content #loginContainer {
	height: auto;
	width: 350px;
	margin-right: auto;
	margin-left: auto;
	margin-top: 120px;
	background-color: #FFF;
	border: 4px solid #081000;
}
.classLeft {
}
</style>
<style type="text/css">

<style type="text/css">
p{
	margin-top: 0px;
	padding-bottom: 10px;
	line-height: 21px;
	padding-right: 85px;
	padding-left: 85px;
}
.inputSize {
	width: 150px;
}
.tdDataInput {
	text-align: left;
	font-family: Tahoma, Geneva, sans-serif;
}
    .tableDataLabel {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 10pt;
	text-align: right;
	width: 80px;
	margin-right: auto;
	margin-left: auto;
	padding-right: 5px;
	padding-top: 8px;
	padding-bottom: 8px;
}


.forgotPassword {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 10pt;
	margin-right: 108px;
}
#container #content #loginContainer #forgot {
	text-align: left;
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 10pt;
	width: 200px;
	margin-left: 22px;
	margin-top: 10px;
}
#adminContainer #contentBox #editableRegion #allTextGoesHere #frame #tablePersonal tr .tdDataInput #submit {
}
.classCenter {
	float: none;
	margin-left: 40px;
}
#container #content #loginContainer #tablePersonal {
	margin-top: 40px;
	margin-bottom: 20px;
	margin-left: 30px;
}


.forgot2 {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 10pt;
	text-align: left;
	width: 150px;
}

</style>

</head>

<body>

<div id="container">
  <div id="content">


    <div id="loginContainer">
      <table id="tablePersonal">
      <form action="login.php" method="post" name="thenaame" target="_self">
    <tr>
      <td class="tableDataLabel">Username</td>
      <td class="tdDataInput"><input name="username" type="text" class="class_textbox" value="" maxlength="33" /></td>
    </tr>
    <tr>
      <td class="tableDataLabel">Password</td>
      <td class="tdDataInput"><input name="password" type="password" class="class_textbox" value="" maxlength="33" /></td>
    </tr>
    <tr>
      <td class="tableDataLabel">&nbsp;</td>
      <td class="tdDataInput"><input name="submit" type="submit" id="submit" value="submit"/></td>
    </tr>
    <tr>
      <td colspan="2" class="tableDataLabel"><div id="forgot"><a href="#">Forgot Password?</a></div></td>
      </tr>
  
 
    
    </form>
      </table>
    </div>
    
    
    

  </div>
</div> 
<!--end container -->
</body>
</html>

<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $endtime = $mtime;
   $totaltime = ($endtime - $starttime);
   echo "This page was created in ".$totaltime." seconds";
?>